package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;

import com.ruoyi.system.api.domain.SysDictType;
import com.ruoyi.system.service.ISysDictTypeService;

/**
 * 字典类型内部Controller，实现远程feign接口com.ruoyi.system.api.RemoteSysDictTypeService。
 * 
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/inner/dicttype")
public class SysDictTypeInnerController
{
    @Autowired
    private ISysDictTypeService sysDictTypeService;

    /**
     * 查询字典数据列表
     */
    @InnerAuth
    @GetMapping("/type")
    public R<SysDictType> selectDictTypeByType(String sysDictType)
    {
        SysDictType list = sysDictTypeService.selectDictTypeByType(sysDictType);
        return R.ok(list);
    }

    /**
     * 查询字典数据列表
     */
    @InnerAuth
    @GetMapping("/data")
    public R<List<SysDictData>> selectDictDataByType(String sysDictType)
    {
        List<SysDictData> list = sysDictTypeService.selectDictDataByType(sysDictType);
        return R.ok(list);
    }

    /**
     * 查询字典类型列表
     */
    @InnerAuth
    @GetMapping("/list")
    public R<List<SysDictType>> selectSysDictTypeList(SysDictType sysDictType)
    {
        List<SysDictType> list = sysDictTypeService.selectDictTypeList(sysDictType);
        return R.ok(list);
    }

    /**
     * 获取字典类型详细信息
     */
    @InnerAuth
    @GetMapping(value = "/{dictId}")
    public R<SysDictType> selectSysDictTypeByDictId(@PathVariable("dictId") Long dictId)
    {
        SysDictType sysDictType = sysDictTypeService.selectDictTypeById(dictId);
        return R.ok(sysDictType);
    }

    /**
     * 新增字典类型
     */
    @InnerAuth
    @PostMapping
    public R<Integer> insertSysDictType(@RequestBody SysDictType sysDictType)
    {
        Integer result = sysDictTypeService.insertDictType(sysDictType);
        return R.ok(result);
    }

    /**
     * 修改字典类型
     */
    @InnerAuth
    @PutMapping
    public R<Integer> updateSysDictType(@RequestBody SysDictType sysDictType)
    {
        Integer result = sysDictTypeService.updateDictType(sysDictType);
        return R.ok(result);
    }

    /**
     * 批量删除字典类型
     */
	@InnerAuth
	@DeleteMapping("/{dictIds}")
    public R<Integer> deleteSysDictTypeByDictIds(@PathVariable Long[] dictIds)
    {
        sysDictTypeService.deleteDictTypeByIds(dictIds);
        return R.ok(1);
    }

}
